﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Miris.HumanMilkAnalyser.DataModel;
using Miris.HumanMilkAnalyser.Service;
using Miris.HumanMilkAnalyser.Service.Shared;
using Miris.HumanMilkAnalyser.WPF.Model;

namespace Miris.HumanMilkAnalyser.WPF.ViewModel
{
    public class AnalysisResultViewModel : PatientViewModel
    {
        public AnalysisResult CurrentAnalysisResult { get; protected set; }

        /// <summary>
        /// Initializes a new instance of the AnalysisResultViewModel class.
        /// </summary>
        public AnalysisResultViewModel(IDataService dataService)
            : base(dataService) { }

        /// <summary>
        /// Set the value of AllTestResults property.
        /// </summary>
        /// <param name="analysisResult"></param>
        public void SetAllTestItemResult(AnalysisResult analysisResult)
        {
            CurrentAnalysisResult = analysisResult;

            AllTestResults = new AllTestItemsViewModel(null, (MilkStage)analysisResult.SampleStageType);
            AllTestResults.TestDate = analysisResult.TestDate;
            AllTestResults.TestDateDisplay = analysisResult.TestDate.ToString(GeneralUtility.MediumDateTimeFormat);
            AllTestResults.Fat.TestResult = analysisResult.Fat;
            AllTestResults.CrudeProtein.TestResult = analysisResult.CrudeProtein;
            AllTestResults.CrudeProtein.ExtraInfo = string.Format("含真蛋白{0}", analysisResult.TrueProtein);
            AllTestResults.TrueProtein.TestResult = analysisResult.TrueProtein;
            AllTestResults.Carbohydrate.TestResult = analysisResult.Carbohydrate;
            AllTestResults.TS.TestResult = analysisResult.TS;
            AllTestResults.Energy.TestResult = analysisResult.Energy;
        }

        /// <summary>
        /// The <see cref="AllTestResults" /> property's name.
        /// </summary>
        public const string AllTestResultsPropertyName = "AllTestResults";

        private AllTestItemsViewModel _allTestResults = null;

        /// <summary>
        /// Sets and gets the AllTestResults property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public AllTestItemsViewModel AllTestResults
        {
            get
            {
                return _allTestResults;
            }

            set
            {
                if (_allTestResults == value)
                {
                    return;
                }

                RaisePropertyChanging(AllTestResultsPropertyName);
                _allTestResults = value;
                RaisePropertyChanged(AllTestResultsPropertyName);
            }
        }
    }
}
